package com.xlyy.modbus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xlyy.modbus.entity.MyData;
import com.xlyy.modbus.entity.MyTestresult;
import com.xlyy.modbus.mapper.MyTestresultMapper;
import com.xlyy.modbus.service.IMyDataService;
import com.xlyy.modbus.service.IMyTestresultService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xlyy.modbus.utils.fn.asserts.Vsserts;
import com.xlyy.modbus.vo.MyTestresultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoucanji
 * @since 2024-05-16
 */
@Service
public class MyTestresultServiceImpl extends ServiceImpl<MyTestresultMapper, MyTestresult> implements IMyTestresultService {
    @Autowired
    private IMyDataService myDataService;

    @Override
    public MyTestresult getMyTestresult(String pch) {
        LambdaQueryWrapper<MyTestresult> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MyTestresult::getPch,pch);
        List<MyTestresult> dbList = this.list(lambdaQueryWrapper);
        System.out.println(dbList+"======dbList");
        return dbList.size()==0?null:dbList.get(0);
    }

    @Override
    public boolean saveUpdate(MyTestresult myTestresult) {
        return this.saveOrUpdate(myTestresult);
    }

    @Override
    public MyTestresult lastMyTestresult() {
        LambdaQueryWrapper<MyTestresult> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(MyTestresult::getId);
        lambdaQueryWrapper.last("limit 1");
        List<MyTestresult> list = this.list(lambdaQueryWrapper);

        return list.size()==0?null:list.get(0);
    }

    @Override
    public IPage<MyTestresult> findMyTestresultPage(MyTestresultVo myTestresultVo) {
        Page<MyTestresult> page = new Page<>(myTestresultVo.getPageNo(),myTestresultVo.getPageSize());
        LambdaQueryWrapper<MyTestresult> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Vsserts.isNotEmpty(myTestresultVo.getKtbh()),MyTestresult::getKtbh,myTestresultVo.getKtbh());
        lambdaQueryWrapper.between(Vsserts.isNotEmpty(myTestresultVo.getStartTime()),MyTestresult::getCrateTime,myTestresultVo.getStartTime(),myTestresultVo.getEndTime());
        lambdaQueryWrapper.eq(Vsserts.isNotEmpty(myTestresultVo.getBysj()),MyTestresult::getBysj,myTestresultVo.getBysj());
        lambdaQueryWrapper.like(Vsserts.isNotEmpty(myTestresultVo.getSlqi()),MyTestresult::getSlqi,myTestresultVo.getSlqi());
        lambdaQueryWrapper.like(Vsserts.isNotEmpty(myTestresultVo.getHgbxqk()),MyTestresult::getHgbxqk,myTestresultVo.getHgbxqk());
        lambdaQueryWrapper.like(Vsserts.isNotEmpty(myTestresultVo.getYcqk()),MyTestresult::getYcqk,myTestresultVo.getYcqk());
        lambdaQueryWrapper.eq(Vsserts.isNotEmpty(myTestresultVo.getSyjg()),MyTestresult::getSyjg,myTestresultVo.getSyjg());
        lambdaQueryWrapper.like(Vsserts.isNotEmpty(myTestresultVo.getSyy()),MyTestresult::getSyy,myTestresultVo.getSyy());
        lambdaQueryWrapper.like(Vsserts.isNotEmpty(myTestresultVo.getJyy()),MyTestresult::getJyy,myTestresultVo.getJyy());
        lambdaQueryWrapper.eq(Vsserts.isNotEmpty(myTestresultVo.getCategorize()),MyTestresult::getCategorize,myTestresultVo.getCategorize());
        lambdaQueryWrapper.orderByDesc(MyTestresult::getId);
        IPage<MyTestresult> results = this.page(page,lambdaQueryWrapper);
        return results;
    }

    @Override
    public int clearTableTestresult() {
        return this.baseMapper.clearTableTestresult();
    }


}
